// ANSWER: 2252639041804718029

#include <iostream>
#include <vector>

static long long find_sum(long long n)
{
	std::vector<long long> F;
	F.push_back(1);
	F.push_back(1);
	F.push_back(2);
	std::vector<long long> s;
	s.push_back(0);
	s.push_back(1);
	s.push_back(2);

	int k = 2;
	while (F[k] <= n)
	{
		k++;
		F.push_back(F[k-1] + F[k-2]);
		s.push_back(s[k-1] + s[k-2] + F[k-2] - 1);
	}
	k--;

	long long sum = s[k] + (n - F[k]);
	while ((n -= F[k]) > 0)
	{
		while (F[k] > n)
			k--;
		sum += s[k] + (n - F[k]);
	}
	return sum;
}

void solve_problem_297()
{
#if 0
	long long n = 999999;
#else
	long long n = 99999999999999999LL;
#endif
	std::cout << find_sum(n) << std::endl;
}
